const { CleanWebpackPlugin } = require("clean-webpack-plugin")
const htmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const path = require ("path")

module.exports = {
    mode:"none",
    entry:{
        "card/card":"./example/card/src/main.js",
        "cart/cart":"./example/cart/src/main.js",
        "home/home":"./example/home/src/main.js",
        "message/message":"./example/message/src/main.js"
    },
    output:{
        filename:"[name].js",// 通过[name]这种占位符的方式动态输出文件名，[name]最终就会替换成打包入口名称
        path:path.resolve(__dirname,"dist")
    },
    module:{
        rules:[
            {
                test:/\.css$/,
                use:[
                    "style-loader",
                    "css-loader"
                ]
            }
        ]
    },
    plugins:[
        new CleanWebpackPlugin(),
        new htmlWebpackPlugin({
            title:"个人资料卡片",
            template:"./example/card/index.html",
            filename: "/card/index.html",
            chunks:['card/card']
        }),
        new htmlWebpackPlugin({
            title:"购物车页面",
            template:"./example/cart/index.html",
            filename: "/cart/index.html",
            chunks:['cart/cart']
        }),
        new htmlWebpackPlugin({
            title:"商城主页面",
            template:"./example/home/index.html",
            filename: "/home/index.html",
            chunks:['home/home']
        }),
        new htmlWebpackPlugin({
            title:"消息页面",
            template:"./example/message/index.html",
            filename: "/message/index.html",
            chunks:['message/message']
        }),
        new CopyWebpackPlugin({
                patterns:[                              // 2.实例化插件
                    // 3.  数组里每一个对象都是一个赋值规则  ，to相对的就是输出目录dist 所以 to后面的目录就不用再写dist了  ，to: "./" 表示直接放到输入目录dist 文件夹下
                    {from:"./example/card/public",to:"./card/pubic"},
                    {from:"./example/cart/public",to:"./cart/pubic"},
                    {from:"./example/home/public",to:"./home/pubic"},
                    {from:"./example/message/public",to:"./message/pubic"}
                ]
        })
    ]

}
